home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 39 / Issue 39.iso / pc / PCSoftware / RoboHelp / DISK1 / DATA.1 / ShowWebHelp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-30  |  4.8 KB  |  179 lines

  1. // eHelpÆ Corporation
  2. // Copyright© 1998-2000 eHelpÆ Corporation.All rights reserved.
  3. // ShowWebHelp.cpp
  4. // The Helper function for WebHelp Content Sensitive Help
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9. #ifdef WIN32
  10. #include <windows.h>
  11. #else // WIN32 probably Unix. here we include a header file for unix.
  12. #include <unistd.h>
  13. #endif
  14.  
  15. #include "showWebHelp.h"
  16.  
  17. int ShowWebHelp(const char* pszCshFileName, int nTopicNumber, const char* pszTopicID, const char *pszRemoteURL)
  18. //        int nWindowOption, int nTop, int nLeft, int nHeight, int nWidth)
  19. {
  20.     char szExePathName[_MAX_PATH + _MAX_PATH + _MAX_PATH];
  21.     char szFullCshFileName[_MAX_PATH + 1];
  22.     char szBuf[32];
  23.     char szTopicParam[_MAX_PATH];
  24.     char szConvertURL[_MAX_PATH];
  25.     char *pColon;
  26. //    char strTop[20], strScreenY[20], strLeft[20], strScreenX[20], strHeight[20], strWidth[20], strOuterHeight[20], strOuterWidth[20];
  27. #ifdef WIN32
  28.     HINSTANCE hInstance;
  29. #endif // WIN32
  30.  
  31.     if (pszCshFileName == NULL || strlen(pszCshFileName) >= _MAX_PATH) return 0;
  32.     if (pszRemoteURL != NULL && strlen(pszRemoteURL) >= _MAX_PATH - 20) return 0;
  33.     if (pszTopicID != NULL && strlen(pszTopicID) >= _MAX_PATH - 10) return 0;
  34.  
  35.     szTopicParam[0] = '\0';
  36.     
  37.     if ((pszTopicID != NULL) && (pszTopicID[0] != 0x00)) {
  38.         strcat(szTopicParam,"#");
  39.         strcat(szTopicParam, "TopicId=");
  40.         strcat(szTopicParam, pszTopicID);
  41.     }
  42.     else if (nTopicNumber != -1)
  43.     {
  44.         strcat(szTopicParam,"#");
  45.         sprintf(szBuf,"%d",nTopicNumber);
  46.         strcat(szTopicParam, "TopicNumber=");
  47.         strcat(szTopicParam,szBuf);
  48.     }
  49.     else if ((pszRemoteURL != NULL) && (pszRemoteURL[0] != 0x00)) {
  50.         strcat(szTopicParam,"#");
  51.         strcat(szTopicParam, "RemoteURL=");
  52.         // we have to convert :// to %072%057%057  otherwise browser will get confused. 
  53.         // the javascript inside the _csh.htm will convert it back.
  54.         strcpy(szConvertURL, pszRemoteURL);
  55.         pColon = strstr(szConvertURL, "://");
  56.         if (pColon != NULL) {
  57.             pColon[0] = '\0';
  58.             strcat(szConvertURL, "%072%057%057");
  59.             strcat(szConvertURL, pszRemoteURL + (pColon - szConvertURL) + 3);
  60.         }
  61.         strcat(szTopicParam, szConvertURL);
  62.     }
  63. /*            // build Windows Option String....    
  64.     if (nWindowOption & WOF_LOCATION) {
  65.         strcat(szTopicParam, ",location=yes");
  66.     }
  67.     else {
  68.         strcat(szTopicParam, ",location=no");
  69.     }
  70.  
  71.     if (nWindowOption & WOF_LOCATION) {
  72.         strcat(szTopicParam, ",location=yes");
  73.     }
  74.     else {
  75.         strcat(szTopicParam, ",location=no");
  76.     }
  77.  
  78.     if (nWindowOption & WOF_MENUBAR) {
  79.         strcat(szTopicParam, ",menubar=yes");
  80.     }
  81.     else {
  82.         strcat(szTopicParam, ",menubar=no");
  83.     }
  84.  
  85.     if (nWindowOption &WOF_RESIZABLE) {
  86.         strcat(szTopicParam, ",resizable=yes");
  87.     }
  88.     else {
  89.         strcat(szTopicParam, ",resizable=no");
  90.     }
  91.  
  92.     if (nWindowOption &WOF_TOOLBAR) {
  93.         strcat(szTopicParam, ",toolbar=yes");
  94.     }
  95.     else {
  96.         strcat(szTopicParam, ",toolbar=no");
  97.     }
  98.  
  99.     if (nWindowOption &WOF_STATUS) {
  100.         strcat(szTopicParam, ",status=yes");
  101.     }
  102.     else {
  103.         strcat(szTopicParam, ",status=no");
  104.     }
  105.  
  106.     if (nWindowOption &WOF_SCROLLBARS) {
  107.         strcat(szTopicParam, ",scrollbars=yes");
  108.     }
  109.     else {
  110.         strcat(szTopicParam, ",scrollbars=no");
  111.     }
  112.  
  113.     sprintf(strTop, ",top=%d", nTop);
  114.     strcat(szTopicParam, strTop);
  115.     sprintf(strScreenY, ",screenY=%d", nTop);
  116.     strcat(szTopicParam, strScreenY);
  117.  
  118.     sprintf(strLeft, ",left=%d", nLeft);
  119.     strcat(szTopicParam, strLeft);
  120.     sprintf(strScreenX, ",screenX=%d", nLeft);
  121.     strcat(szTopicParam, strScreenX);
  122.  
  123.     sprintf(strHeight, ",height=%d", nHeight);
  124.     strcat(szTopicParam, strHeight);
  125.     sprintf(strOuterHeight, ",outerHeight=%d", nHeight);
  126.     strcat(szTopicParam, strOuterHeight);
  127.  
  128.     sprintf(strWidth, ",width=%d", nWidth);
  129.     strcat(szTopicParam, strWidth);
  130.     sprintf(strOuterWidth, ",outerWidth=%d", nWidth);
  131.     strcat(szTopicParam, strOuterWidth);*/
  132.  
  133. #ifdef WIN32
  134.     hInstance = FindExecutable(pszCshFileName,NULL,szExePathName);
  135.   
  136.     if ((int)hInstance > 32) {
  137.         if (GetFullPathName(pszCshFileName, _MAX_PATH, szFullCshFileName, NULL)) {
  138.  
  139.             strcat(szExePathName, " ");
  140.             strcat(szExePathName, szFullCshFileName);
  141.  
  142.             strcat(szExePathName, szTopicParam);
  143.  
  144.             WinExec(szExePathName,SW_SHOW);
  145.         }
  146.         else
  147.             return 0;
  148.  
  149.     }
  150.     else 
  151.         return 0;
  152. #else // UNIX probably
  153.     if (-1 != execl("netscape", szTopicParam, NULL)) 
  154.         return 1;
  155.     else return 0;
  156. #endif
  157.     return 1;
  158. }
  159.  
  160.  
  161. // Here is a tiny Sample
  162. // africa_csh.htm must exist in the same folder as the exe file of this sample.
  163. //#include <stdio.h>
  164. //#include <conio.h> 
  165. //main()
  166. //{
  167. //    printf("press any key to run the test. (Topic Number)\n");
  168. //    getch();
  169. //    ShowWebHelp("africa_csh.htm", 1, NULL, NULL);
  170. //
  171. //    printf("press any key to run the test. (Topic Id)\n");
  172. //    getch();
  173. //    ShowWebHelp("africa_csh.htm", -1, "TopicID1", NULL);
  174. //
  175. //    printf("press any key to run the test. (RemoteURL)\n");
  176. //    getch();
  177. //    ShowWebHelp("africa_csh.htm", -1, NULL, "http://www.ehelp.com");
  178. //    return 1;
  179. //}